/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * @author 品讯科技
 */
package com.px.pa.modulars.circle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.px.pa.modulars.circle.entity.CircleTestScore;
import com.px.pa.modulars.circle.mapper.CircleTestScoreMapper;
import com.px.pa.modulars.circle.service.CircleTestScoreService;
import com.px.pa.modulars.circle.vo.CircleTestScoreVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 人员考试成绩记录表
 *
 * @author 品讯科技
 * @date 2024-08
 */
@Service
public class CircleTestScoreServiceImpl extends ServiceImpl<CircleTestScoreMapper, CircleTestScore> implements CircleTestScoreService {

    @Resource
    private CircleTestScoreService circleTestScoreService;
    @Resource
    private CircleTestScoreMapper circleTestScoreMapper;
    @Override
    public void addScord(CircleTestScore circleTestScore) {
      CircleTestScore circleTestScore1 =  circleTestScoreService.getOne(new QueryWrapper<CircleTestScore>().eq("examination_paper",circleTestScore.getExaminationPaper())
        .eq("learning_backage",circleTestScore.getLearningBackage()).eq("uid",circleTestScore.getUid()));
      if(circleTestScore1 == null){

          circleTestScore.setCreateTime(LocalDateTime.now());
          circleTestScoreService.save(circleTestScore);
      }else {
          circleTestScoreService.updateById(circleTestScore);
      }

    }

    @Override
    public CircleTestScoreVo getSort(Integer id, Integer uid) {

        return circleTestScoreMapper.getSort(id,uid);
    }
}
